<template>
  <published-list :otherListMethod="loadList" :title="title || '我的收藏'" ref="main"></published-list>
</template>

<script>
import PublishedList from '@v/publishedList/PublishedList'
/**
 * 这个页面还是咨询列表的模板组件。通过otherApiUrl参数替换api路径，因为两个接口返回的数据格式都是一样的
 */
export default {
  components: {
    PublishedList
  },

  props: ['otherApiUrl', 'title'],

  data (){
    return {
      
    }
  },

  watch: {
    $route (to, from){
      if(from.name === 'index/my' && to.name === 'collectedList'){
        this.reload()
      }
    }
  },

  methods: {
    reload (){
      this.$refs.main.reload()
    },

    loadList (type, page, isSwipeDownRefresh){
      var seek_type = ''
      if(type === 'usedCar') type = 'used_car'
      if(type === 'seekCar'){
        type = 'seek'
        seek_type = 2
      }
      if(type === 'seekPerson'){
        type = 'seek'
        seek_type = 1
      }

      return _api(this.otherApiUrl ? this.otherApiUrl : 'collect/getListByCon', {
        level: '0,1',
        f_table: type,
        seek_type,
        page: isSwipeDownRefresh ? 1 : page,
      }).then(data =>{
        // 从该接口拿到的数据结构和别的不一样，手动修改一下格式
        data.data = data.data.map(val => {
          return ({ ...val[type], user: val.user })
        })
        return Promise.resolve(data)
      }).catch(e =>{
        console.log(e)
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>